<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_em0131
 * @copyright   Copyright (c) 2014 EMthemes (www.emthemes.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>

<?php	
	$setting = Mage::helper('themeframework/settings');
    $isMobile = $setting->checkMobilePhp();
 ?>

<?php if($setting->getGeneral_ShowPopup()!=0 && $isMobile==false) :?>	
<div class="modal fade em-popup-modal" role="dialog" aria-labelledby="em-popup">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
			<a href="javascript:void(0);" title="<?php echo $this->__('Close') ?>" class="close close-empopup" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></a>        
      </div>
      <div class="modal-body">
        	<div class="popup-content" id="em-popup">	
				<?php if($setting->getGeneral_ShowPopup()==1): ?>
					<?php $login = new Mage_Customer_Block_Form_Login(); ?>
						<?php if (Mage::getSingleton('customer/session')->isLoggedIn()==0): ?>
						<div class="em-account-popup">        
							<form action="<?php echo $login->getPostActionUrl() ?>" method="post" id="em-popup-loginform">
								<?php echo $this->getBlockHtml('formkey'); ?>
								<div class="block-content em-line-01">
									<p class="login-title h3 primary"><?php echo $this->__('Login') ?></p>
									<p class="login-desc normal"><?php echo $this->__('If you have an account with us, please log in.') ?></p>
									<ul class="form-list">
										<li>
											<label for="mini-login"><?php echo $this->__('Email Address') ?><em><?php echo $this->__('*') ?></em></label>
											<input type="text" name="login[username]" value="<?php echo $this->escapeHtml($this->getUsername()) ?>" id="mini-email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
										</li>
										<li>
											<label for="mini-password"><?php echo $this->__('Password') ?><em><?php echo $this->__('*') ?></em></label><input type="password" name="login[password]" class="input-text required-entry validate-password" id="mini-pass" title="<?php echo $this->__('Password') ?>" />
										</li>  
										
									</ul>
									<div class="action-forgot">
										<div class="login_forgotpassword">
											<p><a href="<?php echo $login->getForgotPasswordUrl() ?>"><?php echo $this->__('Forgot Your Password?') ?></a></p>                                                
											<p><a class="create-account-link-wishlist" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).'customer/account/create/'; ?>"><?php echo $this->__("Don't have an account") ?></a></p>
										</div>	
										<div class="actions">
											<button type="submit" class="button"><span><span><?php echo $this->__('Login') ?></span></span></button>
											<p class="required"><?php echo $this->__('* Required Fields') ?></p>
										</div>  					
									</div>
								</div>
							</form> 
						</div>
						<script type="text/javascript">
						//<![CDATA[
							var emPopupLoginForm = new VarienForm('em-popup-loginform', true);
						//]]>
						</script>
					<?php endif;?>
				<?php elseif ($setting->getGeneral_ShowPopup()==2):  ?>
					<?php echo $this->getChildHtml('popup.newsletter');?>
				<?php endif; ?>
				<div class="popup-content-block">
					<?php echo $this->getChildHtml('em_popup_content'); ?>
				</div>
			</div>		
		</div>	
      </div>      
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->		

<?php
	/* lie 只在首页显示 */
	$moduleName 	= $this->getRequest()->getModuleName();
	$controllerName = $this->getRequest()->getControllerName();
	$actionName 	= $this->getRequest()->getActionName();
	
	if($moduleName == 'cms' && $controllerName == 'index' && $actionName == 'index') :
?>
<script type="text/javascript">
//<![CDATA[

	(function($) {        	
		function showPopUpLogin(){
			var $_checkpopup = $('#em-popup');
			if ($_checkpopup.length > 0) {
				var $_popup = $('body').find('.em-popup-modal');
				$_popup.modal("show");                   
				$_popup.on('shown.bs.modal', function () {
					var modal = $(this);						
					dialog = modal.find('.modal-dialog');
					modal.css('display', 'block');				        
					dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 2));
					$('.modal-body',this).css({width:'auto',height:'auto', 'max-height':'100%'});
				});	
			}
		}
		$(document).ready(function(){
			var now = new Date();
			var time = now.getTime();
			var expireTime = time + <?php echo Mage::getStoreConfig('web/cookie/cookie_lifetime')*1000; ?>;
			 now.setTime(expireTime);
			
			if(!Mage.Cookies.get("empopup")){
				document.cookie = 'empopup=true;expires='+now.toGMTString();
				setTimeout(showPopUpLogin,10000);
			}	
			
		});
	})(jQuery);
//]]>
</script>
<?php endif;/* lie 只在首页显示 */?>

<?php endif; ?>
